﻿Imports System.Security.Cryptography
Imports System.Text
Imports DevExpress.XtraSplashScreen

Public Class TaiKhoanHeThong
    Dim Flag As Boolean
    Dim MaNhomTaiKhoanHeThong As String
    Private Sub TaiKhoanHeThong_Activated(sender As Object, e As EventArgs) Handles Me.Activated
        If Flag Then
            Me.NhomTaiKhoanHeThongTableAdapter.Fill(Me.PCV_CLINICDataSet_Don.NhomTaiKhoanHeThong)
            Me.NhomISearchLookupEdit.EditValue = MaNhomTaiKhoanHeThong
            Me.Flag = False
        End If
    End Sub
    Private Sub TaiKhoanHeThong_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
        SplashScreenManager.ShowForm(GetType(WaitForm1))
        Me.NhomTaiKhoanHeThongTableAdapter.Fill(Me.PCV_CLINICDataSet_Don.NhomTaiKhoanHeThong)
        Me.TaiKhoanHeThongTableAdapter.Fill(Me.PCV_CLINICDataSet_Don.TaiKhoanHeThong)
        SplashScreenManager.CloseForm()
    End Sub
    Public Sub New()
        InitializeComponent()
        Me.setObj(Me.PCV_CLINICDataSet_Don, Me.PCV_CLINICDataSet_Don.TaiKhoanHeThong, Me.TaiKhoanHeThongBindingSource, Me.TableAdapterManager, Me.TaiKhoanHeThongTableAdapter, Me.MaITextEdit)
    End Sub
    Private Function base64Encode(ByVal sData As String) As String
        Try
            Dim encData_byte As Byte() = New Byte(sData.Length - 1) {}
            encData_byte = System.Text.Encoding.UTF8.GetBytes(sData)
            Dim encodedData As String = Convert.ToBase64String(encData_byte)
            Return (encodedData)
        Catch ex As Exception
            Throw (New Exception("Error in base64Encode" & ex.Message))
        End Try
    End Function
    Public Function MD5Encrypt(ByVal str As String) As String
        Dim md5 As MD5CryptoServiceProvider
        Dim bytValue() As Byte
        Dim bytHash() As Byte
        Dim strOutput As String = ""
        Dim i As Integer

        ' Create New Crypto Service Provider Object
        md5 = New MD5CryptoServiceProvider

        ' Convert the original string to array of Bytes
        bytValue = System.Text.Encoding.UTF8.GetBytes(str)

        ' Compute the Hash, returns an array of Bytes
        bytHash = md5.ComputeHash(bytValue)
        md5.Clear()

        For i = 0 To bytHash.Length - 1
            'don't lose the leading 0
            strOutput &= bytHash(i).ToString("x").PadLeft(2, "0")
        Next

        MD5Encrypt = strOutput
    End Function

    Public Overrides Sub setSubTruoc_Luu()
        If Me.BarCheckItemNhapTuDanhSach.Checked Then
            Me.IGridView1.SetFocusedRowCellValue("matkhau", Me.base64Encode(Me.IGridView1.GetFocusedRowCellValue("ma")))
        Else
            Me.MatkhauITextEdit.EditValue = Me.base64Encode(Me.MatkhauITextEdit.EditValue)
        End If
    End Sub
    Private Sub NhomISearchLookupEdit_AddNewValue(sender As Object, e As DevExpress.XtraEditors.Controls.AddNewValueEventArgs) Handles NhomISearchLookupEdit.AddNewValue
        NhomTaiKhoanHeThong.Show()
        NhomTaiKhoanHeThong.MdiParent = Me.MdiParent
        NhomTaiKhoanHeThong.WindowState = FormWindowState.Maximized
        Flag = True
    End Sub
    Public Sub setMaNhomTaiKhoanHeThong(ByVal sMaNhomTaiKhoanHeThong As String)
        Me.MaNhomTaiKhoanHeThong = sMaNhomTaiKhoanHeThong
    End Sub
End Class
